﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ITM495.OOExamples.Core.Logger;

namespace ITM495.OOExamples.Core.Linq
{
    public class LinqController: IController
    {
        private ILogger logger = LogManager.GetLogger();

        #region IController Members

        public void Run(Options options)
        {
            logger.Log("In Linq controller.");

            var items = CreateList();


            var result = items.AsQueryable().CreateDateGreatThan(DateTime.Now.AddDays(-8));
            
            foreach(var item in result)
            {
                logger.Log("Found: {0}".ToUpper(), item.Name.UpperCase());
            }
        }

        private IQueryable<MyItem> PageResult(IQueryable<MyItem> items, int start, int  take)
        {
            return items.Skip(start).Take(take);
        }

        private IList<MyItem> CreateList()
        {
            return new List<MyItem>()
                       {
                           new MyItem(){Name = "John Doe",Address = "123 Main St",CreateDate = DateTime.Now.AddDays(-7), LastModifiedDate = DateTime.Now},
                           new MyItem(){Name = "Jane Doe",Address = "123 Main St",CreateDate = DateTime.Now.AddDays(-7), LastModifiedDate = DateTime.Now},
                           new MyItem(){Name = "Junior Doe",Address = "123 Main St",CreateDate = DateTime.Now.AddDays(-7), LastModifiedDate = DateTime.Now},
                           new MyItem(){Name = "Sally Doe",Address = "123 Main St",CreateDate = DateTime.Now.AddDays(7), LastModifiedDate = DateTime.Now},
                       };
        }

        #endregion
    }
}
